const winston = require('winston');
// const { DailyRotateFile  } = require('winston-daily-rotate-file');
const path = require('path')
const { combine, timestamp, printf, json } = winston.format;
const myCustomFormat = printf(({ level, message, timestamp }) => {
    return JSON.stringify({ level, message, timestamp }); // 自定义输出JSON格式
});
// 创建 logger 实例并配置
const logger = winston.createLogger({
    // level: 'info',
    format: combine(
        timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), // 添加时间戳
        myCustomFormat
    ),
    transports: [
        // new winston.transports.Console(),
        new winston.transports.File({ filename: path.resolve(__dirname, 'error.log'), level: 'error' }),
        new winston.transports.File({ filename: path.resolve(__dirname, 'combined.log') })
        // new DailyRotateFile({
        //     filename: 'logs/application-%DATE%.log',
        //     datePattern: 'YYYY-MM-DD',
        //     maxSize: '20m', // 设置日志文件的最大大小为20MB
        //     maxFiles: '14d' // 设置日志文件的最大保存天数为14天
        // })
    ]
});
// if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
    level: 'info' // 设置控制台输出的最低级别为 warn
}));
// }

module.exports = logger
